﻿@model SrBBSPro.Entities.User
@{
    ViewBag.Title = "设置";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}

<div class="main layui-clear" style="min-height: 600px;">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>帐号设置</legend>
    </fieldset>
    <div class="fly-tab user-tab">
        <span id="LAY-mine">
            <a href="javascript:;" class="tab-this" hash="info">我的资料</a>
            <a href="javascript:;" hash="avatar">头像</a>
            <a href="javascript:;" hash="pass">密码</a>
        </span>
    </div>
    <div class="user-mine">
        <div class="layui-form layui-form-pane mine-view" style="display:block;">
            <form action="@Url.Action("Set","Account")" method="post">
                @Html.AntiForgeryToken()
                <div class="layui-form-item">
                    <label for="StaffNo" class="layui-form-label">工号</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Id" name="Id" required lay-verify="required" autocomplete="off" value="@Model.Id" class="layui-input" readonly="readonly" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username" class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="StaffName" name="StaffName" required lay-verify="required" autocomplete="off" value="@Model.StaffName" class="layui-input" />
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            @{
                                var chm = Model.Gender == "1" ? "checked" : "";
                                var chw = Model.Gender != "1" ? "checked" : "";
                            }
                            <i class="layui-icon layui-icon-male" style="color:#10B1EF"></i><input type="radio" name="gender" value="1" @chm title="男">
                            <i class="layui-icon layui-icon-female" style="color:#FF0000"></i><input type="radio" name="gender" value="2" @chw title="女">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_city" class="layui-form-label">部门</label>
                    <div class="layui-input-inline">
                        <select id="Depart" name="Depart">
                            <option value="1">一部</option>
                            <option value="2">二部</option>
                            <option value="3">三部</option>
                            <option value="4">四部</option>
                            <option value="5">五部</option>
                            <option value="6">六部</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="L_sign" class="layui-form-label">签名</label>
                    <div class="layui-input-block">
                        <textarea placeholder="随便写些什么刷下存在感" id="L_sign" name="sign" autocomplete="off" class="layui-textarea" style="height: 80px;">@Model.Sign</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-normal" lay-filter="mine" lay-submit>确认修改</button>
                </div>
            </form>
        </div>
        <div class="layui-form layui-form-pane mine-view">
            <div class="layui-form-item">
                <div class="layui-upload-drag" id="drag" style="width:311px">
                    <i class="layui-icon">&#xe67c;</i>
                    <p>点击上传，或将文件拖拽到此处</p>
                </div>
                <div class="avatar-add">
                    <p>建议尺寸168*168，支持jpg、png、gif，最大不能超过30KB</p>
                    <img src="@Model.HeadPortrait" id="pic">
                    <span class="loading"></span>
                </div>
            </div>
        </div>
        <div class="layui-form layui-form-pane mine-view">
            <form action="@Url.Action("Repass","Account")" method="post">
                @Html.AntiForgeryToken()
                <div class="layui-form-item">
                    <label for="L_nowpass" class="layui-form-label">当前密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_nowpass" name="nowpass" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">新密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_pass" name="pass" required lay-verify="pass" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">确认密码</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_repass" name="repass" required lay-verify="repass" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-normal" lay-filter="mine" lay-submit>确认修改</button>
                </div>
            </form>
        </div>
    </div>
</div>

@section scripts{
    <script>
        layui.use(['layer', 'form', 'validator', 'upload'], function () {
            var layer = layui.layer
                , $ = layui.jquery
                , form = layui.form
                , validator = layui.validator
                , upload = layui.upload;

            form.verify({
                pass: function (value) {
                    if (value.length == 0) {
                        return '密码不能为空！';
                    }
                    if (!validator.IsStringLength(value, 6, 16)) {
                        return '密码在6到16个字符之间';
                    }
                    var nowpass = $('form').find('input[name=nowpass]').val();
                    if (nowpass == value) {
                        return '新密码跟原密码不能相同';
                    }
                },
                repass: function (value) {
                    var pass = $('form').find('input[name=pass]').val();
                    if (pass !== value) {
                        return '两次密码输入不一致';
                    }
                }
            });

            upload.render({
                elem: '#drag'
                , url: '@Url.Action("Upload", "Account")'
                , done: function (res) {
                    if (res.status == 0) {
                        $("img").attr("src", res.url);
                        layer.msg(res.msg, { icon: 1 });
                    } else {
                        layer.msg(res.msg, { icon: 5 });
                    }
                }
            });
            $("#Depart").val("@Model.Depart")
            form.render("select");

            form.on('submit(mine)', function (data) {
                var action = $(data.form).attr('action')
                $.post(action, data.field, function (res) {
                    if (res.status == 1) {
                        layer.msg(res.msg, { icon: 2 });
                    } else {
                        layer.msg(res.msg, { icon: 1, time: 1000 }, function (index) {
                            layer.close(index);
                        });
                    }
                }, 'json');
                return false;
            });
        });
    </script>

}